package com.yh.csx.bsf.flow.engine;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.yh.csx.bsf.flow.core.db.DbHelper;
import com.yh.csx.bsf.flow.dao.dal.t_task_dal;
import com.yh.csx.bsf.flow.engine.state.StateEngine;
import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: chejiangyi
 * @version: 2019-10-31 18:46
 * 超时任务扫描
 **/
@Slf4j
@JobHandler("timeoutJob")
public class TimeoutJob extends IJobHandler {
    @Override
    public ReturnT<String> execute(String param) throws Exception {
        List<Integer> taskids = DbHelper.get(c-> new t_task_dal().getTimeoutList(c));
        for (val id:taskids){
            try {
                new StateEngine().triggerTimeout(id);
            }catch (Exception e){
                log.error("超时任务执行出错",e);
            }
        }
        return ReturnT.SUCCESS;
    }
}